package com.wnxy.mallserver.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 对响应的结果进行封装
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResponseResult<T> {

    //定义常量 ，并给通用的code和message赋值
    public static final ResponseResult OK = new ResponseResult(StateCode.SUCCESS, Message.SUCCESS);

    private Integer code;//状态码
    private String message;//消息
    private T data;//响应数据

    //构造方法
    public ResponseResult(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 对构造方法进行在封装
     */
    public ResponseResult(ResponseResult result, T data) {
        this.code = result.getCode();
        this.message = result.getMessage();
        this.data = data;
    }
}
